//统一管理咱们项目用户相关的接口
import request from "@/utils/request";
import type {
    HandleResponseData, UuidsForm,UuidForm
} from "../../common/type";
import {
    DatasourceAddOrUpdateForm,
    DatasourceInfoReponseData,
    DatasourceListReponseData,
    DocGenForm
} from "@/api/sys/datasource/type";

//项目用户相关的请求地址
enum API {

    //分页列表
    pageListDatasourceUrl = "/bg/datasource/pageList",
    //详情
    datasourceInfoUrl = "/bg/datasource/detail",
    //测试连接
    datasourceTestConnectUrl = "/bg/datasource/testConnect",
    //生成文档
    datasourceGenWordUrl = "/bg/datasource/genWord",
    //编辑
    updateDatasourceUrl = "/bg/datasource/update",
    //添加
    addDatasourceUrl = "/bg/datasource/add",
    //删除
    delDatasourceUrl = "/bg/datasource/batchDel",
    //同步数据
    syncDatasourceUrl = "/bg/datasource/sync"
}

export const reqBatchDelDatasource = (uuidsForm: UuidsForm) => request.post<any, HandleResponseData>(API.delDatasourceUrl,uuidsForm)

export const reqDatasourcePageList = (page: number, pageSize: number,datasourceLike: string, connNameLike: string) =>
    request.get<any, DatasourceListReponseData>(API.pageListDatasourceUrl+`?datasourceLike=${datasourceLike}&page=${page}
    &pageSize=${pageSize}&connNameLike=${connNameLike}`)
//测试连接
export const reqDatasourceTestConnect = (uuid: string) => request.get<any, HandleResponseData>(API.datasourceTestConnectUrl+`?uuid=${uuid}`);
//同步数据
export const reqDatasourceSync = (uuid: string) => request.get<any, HandleResponseData>(API.syncDatasourceUrl+`?uuid=${uuid}`);
//生成文档
export const reqDatasourceGenWord = (docGenForm: DocGenForm) => request.post<any, HandleResponseData>(API.datasourceGenWordUrl,docGenForm);
//详情
export const reqDatasourceInfo = (uuid: string) => request.get<any, DatasourceInfoReponseData>(API.datasourceInfoUrl+`?uuid=${uuid}`);
//添加/编辑
export const reqAddOrUpdateDatasource = (data: DatasourceAddOrUpdateForm) => {
    if (data.uuid) {
        return request.post<any, HandleResponseData>(API.updateDatasourceUrl, data);
    } else {
        return request.post<any, HandleResponseData>(API.addDatasourceUrl, data);
    }
}






